def is_prime(n):
    if n <= 1:
        return False
    for i in range(2, int(n ** 0.5) + 1):
        if n % i == 0:
            return False
    return True
def largest_prime_from_number(number):
    largest_prime = 0
    for i in range(len(number)):
        for j in range(i + 1, len(number) + 1):
            substring = number[i:j]
            if is_prime(int(substring)):
                largest_prime = max(largest_prime, int(substring))
    return largest_prime
input_number = input().strip()
if len(input_number) != 4 or not input_number.isdigit():
    print(0)
else:
    result = largest_prime_from_number(input_number)
    print(result)
